#!/usr/bin/python

from tkinter import filedialog as fd
import json as js

def new_saves():
    f=fd.asksaveasfilename(title='另存为',initialdir='saves',filetypes=[('JSON file','.json')])
    if f==None:return None
    if len(f)<=5:
        f+='.json'
    elif f[(len(f)-5):len(f)]!='.json':
        f+='.json'
    return f
def open_saves():
    file=fd.askopenfile(title="请选择存档进行加载",initialdir='saves',filetypes=[('JSON file','.json')],mode='r')
    if file==None:
        return None
    saves=js.load(file)
    file.close()
    return (file.name,saves)
def save_game(filename:str,game:dict):
    with open(file=filename,mode='w',encoding='utf-8') as f:
        js.dump(game,f)